function [beta_ap,lambda_ap]=ap_test(factor,asset,x)
% x=1, include stat in the output; otherwise not
[~,N_shock] = size(factor);
[~,N_asset] = size(asset);

[beta,lambda,se_beta,t_beta,se_lambda,aa,r2,r2_2step] = cross_section(asset,factor);
beta_ap = zeros(N_asset,2*N_shock);
lambda_ap = zeros(2*N_shock+1,1);
beta_ap(:,1:2:end) = beta';
beta_ap(:,2:2:end) = t_beta';
lambda_ap(1:2:end-1,1) = lambda;
lambda_ap(2:2:end-1,1) = lambda./se_lambda;
lambda_ap(end,1) = r2_2step;

exp_ret = nanmean(asset,1);
exp_ret = exp_ret';
std_ret = nanstd(asset,1)/sqrt(4);
std_ret = std_ret';
if x == 1
beta_ap = [exp_ret std_ret beta_ap];
end

end